﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using haunstm_test_mvc_json.Models;

namespace haunstm_test_mvc_json.Controllers
{
    public class Server_To_ClientController : Controller
    {
        //
        // GET: /AjaxFetchJSONFromServer/
        public ActionResult SimpleString()
        {
            return View();
        }

        [HttpPost]
        public string SimpleStringResult()
        {
            var jsonString = "{\"widget\": {" +
                             "    \"debug\": \"on\"," +
                             "  \"window\": {" +
                             "      \"title\": \"Sample Konfabulator Widget\"," +
                             "      \"name\": \"main_window\"," +
                             "      \"width\": 500," +
                             "      \"height\": 500" +
                             "   }," +
                             "   \"imge\": {" +
                             "       \"src\": \"Images/Sun.png\"," +
                             "       \"ame\": \"sun1\"," +
                             "       \"hffset\": 250," +
                             "       \"vOfset\": 250," +
                             "       \"alinment\": \"center\"" +
                             "   }," +
                             "   \"ext\": {" +
                             "       \"data\":\"Click Here\"," +
                             "       \"size\": 6," +
                             "       \"style\": \"bold\"," +
                             "       \"name\": \"txt1\"," +
                             "       \"hOffset\": 50," +
                             "       \"vOffset\": 10," +
                             "       \"alignment\": \"center\"," +
                             "       \"onMouseUp\": \"un1.opacity = (sun1.opacity / 100) * 90;\"" +
                             "   }" +
                             "}}  ";

           return jsonString;
        }

        [HttpPost]
        public string ComplexStringResult()
        {
            var jsonString = "{\"widget\": {" +
                             "    \"debug\": \"on\"," +
                             "  \"window\": {" +
                             "      \"title\": \"Sample Konfabulator Widget\"," +
                             "      \"name\": \"main_window\"," +
                             "      \"width\": 500," +
                             "      \"height\": 500" +
                             "   }," +
                             "   \"imge\": {" +
                             "       \"src\": \"Images/Sun.png\"," +
                             "       \"ame\": \"sun1\"," +
                             "       \"hffset\": 250," +
                             "       \"vOfset\": 250," +
                             "       \"alinment\": \"center\"" +
                             "   }," +
                             "   \"ext\": {" +
                             "       \"data\":\"Click Here\"," +
                             "       \"size\": 6," +
                             "       \"style\": \"bold\"," +
                             "       \"name\": \"txt1\"," +
                             "       \"hOffset\": 50," +
                             "       \"vOffset\": 10," +
                             "       \"alignment\": \"center\"," +
                             "       \"onMouseUp\": \"un1.opacity = (sun1.opacity / 100) * 90;\"" +
                             "   }" +
                             "}}  ";

            return jsonString;
        }

        [HttpGet]
        public ActionResult JSONPersonObject()
        {
            return View();
        }

        [HttpPost]
        public ActionResult JSONPersonObject(string Name)
        {
            var person = new Person
                             {
                                 Id = -1,
                                 FirstName = Name,
                                 LastName = "Anka",
                                 Addresses = new List<Address>  {   new Address {Line1 = "Andvägen 5",City = "Ankeborg", Country = "USA 1"},
                                                                    new Address {Line1 = "Gåsvägen 5",City = "Gåseborg", Country = "USA 2"}
                                                                }
                             };
            var jsonResult = this.Json(person, JsonRequestBehavior.AllowGet);
            return jsonResult;
        }

    }
}
